package com.heima.wemedia.controller.v1;

import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author bo.li
 * @Date 2022/11/10 10:42
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/v1/channel")
@Slf4j
public class WmChannelController {

    @Autowired
    private WmChannelService channelService;

    @GetMapping("/channels")
    public ResponseResult list(){
        return ResponseResult.okResult(channelService.list());
    }

    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmChannel wmChannel){
        return channelService.saveChannel(wmChannel);
    }

    /**
     * 根据channel条件进行分页查询
     *
     * @param dao
     * @return
     */
    @PostMapping("/list")
    public ResponseResult page(@RequestBody ChannelDto dao) {

        log.info("controller接受到的数据为----{}",dao.getPage() +"  " + dao.getSize());

        return channelService.pagelist(dao);
    }

    /**
     * 对channel的修改
     *
     * @param dto
     * @return
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmChannel dto){

        return channelService.updateChannel(dto);
    }

    /**
     * 对频道的删除
     *
     * @param id
     * @return
     */
    @GetMapping("del/{id}")
    public ResponseResult del(@PathVariable("id") Integer id){

        log.info("controller 拿到的id为：{}",id);
        return channelService.del(id);
    }
}